<!-- 岗位管理 -->
<template>
    <div>
        <el-form :inline="true" :model="ruleForm" class="demo-form-inline">
            <el-form-item label="岗位名称：">
                <el-input placeholder="请输入岗位名称" v-model.trim="ruleForm.postname" size="small"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="success" @click="searchList" id="monitorEnter" size="small">查询</el-button>
                <el-button type="primary" @click="newbuilt" size="small">新建岗位</el-button>
                <el-button size="small" type="primary" @click="downExcelHandle">下载导入模版</el-button>
                <a :href="downUrl" ref="downNode" target="_blank"></a>
                <el-button size="small" type="primary" @click="upLoadHandle">批量导入</el-button>
                <input type="file" ref="upLoad" style="display: none;" @change="fileChangeHandle">
            </el-form-item>
        </el-form>

        <el-table :data="tableData" border>
            <el-table-column type="index" label="序号" width="50" align="center"></el-table-column>
            <el-table-column label="岗位" prop="stationName" align="center"></el-table-column>
            <el-table-column label="岗位ID" prop="stationCode" align="center"></el-table-column>
            <el-table-column label="编制数量" prop="compilationQuantity" align="center"></el-table-column>
            <el-table-column label="当前在职数量" prop="currentQuantity" align="center"></el-table-column>
            <el-table-column label="业务线" prop="businessLineName" align="center"></el-table-column>
            <el-table-column label="部门" prop="departmentName" align="center"></el-table-column>
            <el-table-column label="角色" prop="roleName" align="center"></el-table-column>
            <el-table-column label="岗位权重范围" prop="weightOffLine" align="center">
                <template slot-scope="scope">
                    {{scope.row.weightOffLine | addZero}} - {{scope.row.weightOnLine | addZero}}
                </template>
            </el-table-column>
            <el-table-column label="岗位权重标准" prop="standardWeight" align="center">
                <template slot-scope="scope">
                    {{scope.row.standardWeight | addZero}}
                </template>
            </el-table-column>
            <el-table-column label="详细信息" align="center">
                <template slot-scope="scope">
                    <el-button type="text" @click="edithander('push',scope.row)">编辑</el-button>
                </template>
            </el-table-column>
        </el-table>

        <div class="pagebar">
            <el-pagination
                    background
                    layout="total, sizes, prev, pager, next"
                    :current-page.sync="ruleForm.pageNum"
                    :page-sizes="[10, 20, 30, 40]"
                    :page-size="ruleForm.pageSize"
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :total="totalSize">
            </el-pagination>
        </div>

    </div>
</template>

<script>
    import api from '@/api/apiPath'

    export default {
        title: '岗位管理',
        data() {
            return {
                downUrl: api.STAFFSTATIONDOWNLOAD,
                ruleForm: {
                    postname: undefined,
                    pageNum: 0,
                    pageSize: 10,
                },
                totalSize: 0,
                name: "",
                formLabelWidth: '120px',
                tableData: [],
            }
        },
        methods: {
            newbuilt() {
                this.$router.push({path: '/postnewbuilt', query: {type: 'add'}})
            },
            downExcelHandle() {
                this.$refs.downNode.click()
            },
            upLoadHandle() {
                this.$refs.upLoad.value = '' // 每次点击清空上次的值
                this.upTip = ''
                this.$refs.upLoad.click()
            },
            searchList(){
                this.ruleForm.pageNum = 1
                this.getlist()
            },
            getlist() {
                this.axios.post(api.getAllPostPageList, {
                    pageSize: this.ruleForm.pageSize,
                    pageNum: this.ruleForm.pageNum,
                    stationName: this.ruleForm.postname
                }).then((res) => {
                    this.tableData = res.data.data.list;
                    this.totalSize = res.data.data.total;
                })
            },
            handleCurrentChange() {
                this.getlist()
            },
            handleSizeChange(val) {
                this.ruleForm.pageSize = val
                this.getlist();
            },
            edithander(type, row) {
                this.$router.push({path: '/postnewbuilt', query: {type: 'edit', id: row.id}})
            },
            fileChangeHandle() {
                const file = this.$refs.upLoad.files[0]
                if (file) {
                    let param = new FormData()
                    param.append('excelFile', file)
                    this.axios.post(api.STAFFSTATIONUPLOAD, param).then((res)=>{
                          if (res && res.data.code == 200) {
                             this.$message({
                                  message: '导入成功',
                                  type: 'success'
                              });
                              this.getlist();
                          }  
                    })
                }
            },
        },

        filters: {
            addZero(number) {
                return number.toFixed(2);
            },
        },
        activated(){
            this.searchList()
        },
        created() {
            this.getlist()
        }

    }
</script>

<style lang="stylus" scoped>

</style>